package com.example.aop.invocation;

import com.example.aop.proxy.HouseSubject;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
//import org.springframework.cglib.proxy.MethodInterceptor;
//import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CGLIBInterceptor implements MethodInterceptor {
    private Object target;

    public CGLIBInterceptor(Object target) {
        this.target = target;
    }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, net.sf.cglib.proxy.MethodProxy methodProxy) throws Throwable {
        System.out.println("我是中介，开始代理");
        //通过反射调用被代理方法
        Object invoke =methodProxy.invoke(target,objects);
        System.out.println("我是中介，结束代理");
        return invoke;
    }


}
